app.controller("jsoneditCtrl", [
  "$scope",
  "$modal",
  "$filter",
  "$rootScope",
  "lodash",
  "$http",
  function($scope, $modal, $filter, $rootScope, lodash, $http) {
    $rootScope.initBreadcrumb($scope.breadcrumb);
    $scope.breadcrumb.push("JSONedit");

    $scope.customTypes = [
      {
        type: "1"
      },
      {
        type: "2"
      },
      {
        type: "3"
      },
      {
        type: "4"
      }
    ];
    // example JSON
    $scope.jsonData = {
      Name: "Joe",
      "Last Name": "Miller",
      Address: { Street: "Neverland 42" }
    };
    $scope.changeKeys = {
      Name: false,
      "Last Name": false,
      Address: true,
      Street: true
    };

    // console.log(
    //       "11111111111111111111" + JSON.stringify($scope.customTypes)
    //   );
    $scope.$watch(
      "jsonData",
      function(json) {
        $scope.jsonString = $filter("json")(json);

        console.log($scope.jsonString);
        console.log($scope.jsonData);
      },
      true
    );
    $scope.$watch(
      "jsonString",
      function(json) {
        try {
          $scope.jsonData = JSON.parse(json);
          $scope.wellFormed = true;
        } catch (e) {
          $scope.wellFormed = false;
        }
      },
      true
    );
  }
]);
